package com.zx.mq.topic;

import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class TopicSender {

    @Autowired
    AmqpTemplate rabbitTemplate;

    // 生产者
    public void send(String msg){
        send0("00");
        send1("AA");
        send2("BB");
    }

    // QueueA and QueueB
    public void send0(String msg) {
        System.out.println("Sender : " + msg);
        this.rabbitTemplate.convertAndSend("topicExchange", "topic.00", msg);
    }

    // only QueueB
    public void send1(String msg) {
        System.out.println("Sender : " + msg);
        this.rabbitTemplate.convertAndSend("topicExchange", "topic.A", msg);
    }

    // only QueueB
    public void send2(String msg) {
        System.out.println("Sender : " + msg);
        this.rabbitTemplate.convertAndSend("topicExchange", "topic.B", msg);
    }

    // 没有满足queue，丢弃
    public void send3(String msg) {
        System.out.println("Sender : " + msg);
        this.rabbitTemplate.convertAndSend("topicExchange", "xx.C", msg);
    }
}
